home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Binding / NoPart.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  42.3 KB  |  1,563 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        NoPart.cpp
  3.  
  4.     Contains:    Implementation of class NoPart
  5.  
  6.     Owned by:    Reginald Adkins
  7.  
  8.     Copyright:    © 1992 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <11>      10/10/96    RA        Allow embedding in AppleTest_Container
  13.         <10>      10/10/96    EL        1379168,1390679: Get around 68K compiler
  14.                                     problem. 1377804: Use AppFont for drawing
  15.                                     no part message.
  16.          <9>     10/7/96    RA        1382196 NoPart now restores its port,
  17.                                     1367586 scales, 1367891 respects transforms
  18.                                     appropriately, and 1367481 calls
  19.                                     usedshapechanged
  20.          <8>     9/24/96    eeh        1373302: NoPart should deactivate windows
  21.          <7>     7/30/96    eeh        1372943: test for kTranslateItem
  22.          <5>     7/17/96    jpa        1369044: Dispose pixpat in Draw method to
  23.                                     avoid a memory leak.
  24.          <4>     7/11/96    jpa        1364071: Glitch in message if editor name
  25.                                     is non-NULL but empty.
  26.          <3>     6/27/96    jpa        1361886: Kinder, gentler NoPart (display
  27.                                     message to user.) 1361916: Don't force
  28.                                     process to quit in Open method.
  29.          <2>     6/22/96    EL        1344140: in NoPartOpen, do not rebind if it
  30.                                     is root and do not call translation dialog.
  31.  
  32.     In Progress:
  33.         
  34. */
  35.  
  36. #ifndef _PLFMDEF_
  37. #include <PlfmDef.h>
  38. #endif
  39.  
  40. #ifndef _ALTPOINT_
  41. #include <AltPoint.h>            // Use C++ savvy XMPPoint and XMPRect
  42. #endif
  43.  
  44. #ifndef _INFOUTIL_
  45. #include <InfoUtil.h>
  46. #endif
  47.  
  48. #ifndef _ODMATH_
  49. #include <ODMath.h>
  50. #endif
  51.  
  52. #ifndef _TEMPOBJ_
  53. #include <TempObj.h>
  54. #endif
  55.  
  56. #ifndef SOM_NoPart_xh
  57. #include <NoPart.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODFrame_xh
  61. #include <Frame.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODFacet_xh
  65. #include <Facet.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODShape_xh
  69. #include <Shape.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODTransform_xh
  73. #include <Trnsform.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODWindow_xh
  77. #include <Window.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODInfo_xh
  81. #include <Info.xh>
  82. #endif
  83.  
  84. #ifndef SOM_ODFrameFacetIterator_xh
  85. #include "FrFaItr.xh"
  86. #endif
  87.  
  88. #ifndef SOM_ODStorageUnit_xh
  89. #include <StorageU.xh>
  90. #endif
  91.  
  92. #ifndef SOM_ODContainer_xh
  93. #include <ODCtr.xh>
  94. #endif
  95.  
  96. #ifndef SOM_ODSession_xh
  97. #include <ODSessn.xh>
  98. #endif
  99.  
  100. #ifndef SOM_ODDispatcher_xh
  101. #include <Disptch.xh>
  102. #endif
  103.  
  104. #ifndef SOM_ODTranslation_xh
  105. #include <Translt.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODWindowState_xh
  109. #include <WinStat.xh>
  110. #endif
  111.  
  112. #ifndef _BNDNGDEF_
  113. #include <BndngDef.h>
  114. #endif
  115.  
  116. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  117. #include <StdDefs.xh>
  118. #endif
  119.  
  120. #ifndef _SHELLDEF_
  121. #include <ShellDef.h>    /* I use RealShell's error messages (from ErrMsgs.r) */
  122. #endif
  123.  
  124. #ifndef _DLOGUTIL_
  125. #include <DlogUtil.h>
  126. #endif
  127.  
  128. #ifndef _DOCUTILS_
  129. #include <DocUtils.h>
  130. #endif
  131.  
  132. #ifndef _FOCUSLIB_
  133. #include <FocusLib.h>
  134. #endif
  135.  
  136. #ifndef _PASCLSTR_
  137. #include <PasclStr.h>
  138. #endif
  139.  
  140. #ifndef _USERSRCM_
  141. #include <UseRsrcM.h>
  142. #endif
  143.  
  144. #ifndef SOM_ODPartWrapper_xh
  145. #include <PartWrap.xh>
  146. #endif
  147.  
  148. #ifndef _BINDNGH_
  149. #include <BindngH.h>
  150. #endif
  151.  
  152. #ifndef SOM_ODBinding_xh
  153. #include <ODBindng.xh>
  154. #endif
  155.  
  156. #ifndef _BNDNGDEF_
  157. #include <BndngDef.h>
  158. #endif
  159.  
  160. #ifndef _ISOSTR_
  161. #include <ISOStr.h>
  162. #endif
  163.  
  164. #ifndef __ICONS__
  165. #include <Icons.h>
  166. #endif
  167.  
  168. #ifndef __QUICKDRAW__
  169. #include <Quickdraw.h>
  170. #endif
  171.  
  172. #ifndef __RESOURCES__
  173. #include <Resources.h>
  174. #endif
  175.  
  176. #ifndef __DIALOGS__
  177. #include <Dialogs.h>
  178. #endif
  179.  
  180. #ifndef __TEXTUTILS__
  181. #include <TextUtils.h>
  182. #endif
  183.  
  184. #ifndef __TOOLUTILS__
  185. #include <ToolUtils.h>
  186. #endif
  187.  
  188. #ifndef SOM_ODStorageSystem_xh
  189. #include <ODStor.xh>
  190. #endif
  191.  
  192. #ifndef _TRANSUTL_
  193. #include <TransUtl.h>
  194. #endif
  195.  
  196. #ifndef _BNDNSUTL_
  197. #include <BndNSUtl.h>
  198. #endif
  199.  
  200. #ifndef _BINDINGUTILS_
  201. #include <BindingUtils.h>
  202. #endif
  203.  
  204. #pragma segment NoPart
  205.  
  206. #define SOM_Module_nopart_Source
  207. #define VARIABLE_MACROS
  208. #include <NoPart.xih>
  209.  
  210.  
  211. //==============================================================================
  212. // Constants
  213. //==============================================================================
  214.  
  215.  
  216. const short kButtonWidth  = 26;            // Dimensions of button
  217. const short kButtonHeight = 22;
  218.  
  219. const short kButtonPrefTop = 38;        // Preferred position relative to frame top/left
  220. const short kButtonPrefLeft=  0;
  221.  
  222. const short kButtonAltTop  =  0;        // Alternate position if frame too short
  223. const short kButtonAltLeft = 38;
  224.  
  225. const short kMinTextWidth = 48;            // Min dimensions of usable text box
  226. const short kMinTextHeight= 12;
  227.  
  228. const short kTranslateItem    = 2;        // "Translate..." button in alert
  229. const short kErrorNumberItem= 4;
  230.  
  231. const ODError    kFakeErrNoEditorNoName    = -1;
  232. const ODError    kFakeErrNoEditor        = -2;
  233.  
  234.  
  235. //==============================================================================
  236. // Util class
  237. //==============================================================================
  238.  
  239. // Default to black background and white foreground.
  240. class CPenInfo
  241. {
  242.     public:
  243.     CPenInfo(long foreColor, long backColor);
  244.     ~CPenInfo();
  245.     
  246.     protected:
  247.     PenState penState;
  248.     RGBColor foreState, backState;
  249. };
  250.  
  251. CPenInfo::CPenInfo(long foreColor = blackColor, long backColor = whiteColor)
  252. {
  253.     // Save the pen state and set to default
  254.     GetPenState(&penState);        
  255.     PenNormal();        
  256.  
  257.     // Save and set the colors to black/white
  258.     GetForeColor(&foreState);
  259.     GetBackColor(&backState);
  260.     ForeColor(foreColor);
  261.     BackColor(backColor);
  262. }
  263.  
  264. CPenInfo::~CPenInfo()
  265. {
  266.     // Restore original colors and pen state
  267.     SetPenState(&penState);
  268.     RGBForeColor(&foreState);
  269.     RGBBackColor(&backState);
  270. }
  271.  
  272. //==============================================================================
  273. // Variables
  274. //==============================================================================
  275.  
  276.  
  277. static ODIconFamily gButtonIcon = kODNULL;
  278.  
  279.  
  280. //==============================================================================
  281. // Local Functions
  282. //==============================================================================
  283.  
  284.  
  285. static void    TransparentTextBox( void *text, short length, const Rect &box);
  286.  
  287.  
  288. static inline short Width ( const Rect &r )    {return r.right-r.left;}
  289. static inline short Height( const Rect &r )    {return r.bottom-r.top;}
  290.  
  291. // Copied from Peng!
  292. static ODBoolean
  293. ScaleOnlyShape(Environment* ev, ODTransform* t, ODShape* s)
  294. {
  295.     ODMatrix m;
  296.     t->GetMatrix(ev,&m);
  297.     
  298.     m.m[2][0] = 0L; // blast x-coord offset
  299.     m.m[2][1] = 0L; // blast y-coord offset
  300.     
  301.     TRY
  302.         TempODTransform tt = t->NewTransform(ev);
  303.         tt->SetMatrix(ev,&m);
  304.         s->Transform(ev,tt);
  305.         return true;
  306.     CATCH_ALL
  307.     ENDTRY
  308.     return false;
  309. }
  310.  
  311. //==============================================================================
  312. // NoPart
  313. //==============================================================================
  314.  
  315.  
  316. //--------------------------------------------------------------------
  317. // somUninit
  318. //--------------------------------------------------------------------
  319. // No need for SOM_TRY block. somUninit is not allowed to throw.
  320. //--------------------------------------------------------------------
  321.  
  322. SOM_Scope void  SOMLINK NoPartsomUninit(Apple_NoPart *somSelf)
  323. {
  324.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  325.     Apple_NoPartMethodDebug("Apple_NoPart","somUninit");
  326.     
  327.     TRY    
  328.     
  329.     DisposeIText(_fUserMessageEditorName);
  330.     delete _fUserMessageParam;
  331.     
  332.     CATCH_ALL
  333.     ENDTRY
  334.     
  335. }
  336.  
  337.  
  338. //--------------------------------------------------------------------
  339. // Release
  340. //--------------------------------------------------------------------
  341.  
  342. SOM_Scope void  SOMLINK NoPartRelease(Apple_NoPart *somSelf, Environment *ev)
  343. {
  344.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  345.     Apple_NoPartMethodDebug("Apple_NoPart","Release");
  346.     
  347.     SOM_TRY
  348.  
  349.     parent_Release(somSelf, ev);
  350.     if (somSelf->GetRefCount(ev) == 0)
  351.         _fStorageUnit->GetDraft(ev)->ReleasePart(ev, (ODPart*)_fPartWrapper);
  352.     
  353.     SOM_CATCH_ALL
  354.     SOM_ENDTRY
  355. }
  356.  
  357.  
  358. //--------------------------------------------------------------------
  359. // InitPart
  360. //--------------------------------------------------------------------
  361.  
  362. SOM_Scope void  SOMLINK NoPartInitPart(Apple_NoPart *somSelf, Environment *ev,
  363.         ODStorageUnit* storageUnit, ODPart* partWrapper)
  364. {
  365.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  366.     Apple_NoPartMethodDebug("Apple_NoPart","InitPart");
  367.     
  368.     SOM_TRY
  369.  
  370.     parent_InitPart(somSelf, ev, storageUnit, partWrapper);
  371.     
  372.     _fStorageUnit = storageUnit;
  373.     _fPartWrapper = (ODPartWrapper*)partWrapper;
  374.     _fSession = storageUnit->GetSession(ev);
  375.         
  376.     SOM_CATCH_ALL
  377.     SOM_ENDTRY
  378. }
  379.  
  380.  
  381. //--------------------------------------------------------------------
  382. // InitPartFromStorage
  383. //--------------------------------------------------------------------
  384.  
  385. SOM_Scope void  SOMLINK NoPartInitPartFromStorage(Apple_NoPart *somSelf, Environment *ev,
  386.         ODStorageUnit* storageUnit, ODPart* partWrapper)
  387. {
  388.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  389.     Apple_NoPartMethodDebug("Apple_NoPart","InitPartFromStorage");
  390.     
  391.     SOM_TRY
  392.  
  393.     parent_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);
  394.     
  395.     _fStorageUnit = storageUnit;
  396.     _fPartWrapper = (ODPartWrapper*)partWrapper;
  397.     _fSession = storageUnit->GetSession(ev);
  398.     
  399.     SOM_CATCH_ALL
  400.     SOM_ENDTRY
  401. }
  402.  
  403. //--------------------------------------------------------------------
  404. // CalcUsedShape
  405. //--------------------------------------------------------------------
  406.  
  407. SOM_Scope ODShape*  SOMLINK NoPartCalcUsedShape(Apple_NoPart *somSelf, Environment *ev, ODFrame* frame)
  408. {
  409.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  410.     Apple_NoPartMethodDebug("Apple_NoPart","CalcUsedShape");
  411.     
  412.     ODShape* usedShape = kODNULL; ODVolatile(usedShape);
  413.  
  414.     SOM_TRY
  415.  
  416.     ASSERT_NOT_NULL(frame);
  417.         
  418.     ODSession* fSession = ODGetSession(ev, frame);
  419.     
  420.     ODTypeToken view = frame->GetViewType(ev);
  421.  
  422.     if ( view == fSession->Tokenize(ev, kODViewAsLargeIcon) ||
  423.          view == fSession->Tokenize(ev, kODViewAsSmallIcon) ||
  424.          view == fSession->Tokenize(ev, kODViewAsThumbnail) )
  425.     {
  426.         RgnHandle usedRgn = ODNewRgn();
  427.         TRY
  428.             Rect iconRect;
  429.             if ( view == fSession->Tokenize(ev, kODViewAsLargeIcon) || view == fSession->Tokenize(ev, kODViewAsSmallIcon))
  430.             {
  431.                 // Set the bounds rect for the icon size.
  432.                 if (view == fSession->Tokenize(ev, kODViewAsSmallIcon))
  433.                     SetRect(&iconRect, 0, 0, kODSmallIconSize, kODSmallIconSize);
  434.                 else
  435.                     SetRect(&iconRect, 0, 0, kODLargeIconSize, kODLargeIconSize);
  436.  
  437.                 // Convert the icon mask into a Region.
  438.                 if (_fIconFamily == kODNULL)
  439.                     _fIconFamily = ODGetIconFamily(ev, frame);
  440.                 if (!_fIconFamily)
  441.                     WARN("_fIconFamily == kODNULL");
  442.                 else
  443.                     THROW_IF_ERROR( IconSuiteToRgn(usedRgn, &iconRect, kAlignTopLeft, _fIconFamily) );
  444.             }
  445.             else if ( view == fSession->Tokenize(ev, kODViewAsThumbnail ))
  446.             {    
  447.                 SetRect(&iconRect, 0, 0, kODThumbnailSize, kODThumbnailSize);
  448.                     
  449.                 RectRgn(usedRgn,&iconRect);
  450.             }
  451.         
  452.             usedShape = frame->CreateShape(ev);
  453.             usedShape->SetQDRegion(ev, usedRgn);
  454.                             
  455.         CATCH_ALL
  456.             ODSafeReleaseObject(usedShape);
  457.             ODDisposeHandle((ODHandle) usedRgn);
  458.             usedShape = kODNULL;
  459.         ENDTRY
  460.     }
  461.     else if ( view == fSession->Tokenize(ev, kODViewAsFrame))
  462.     {
  463.         //TempODShape shape = frame->AcquireFrameShape(ev, kODNULL);
  464.         usedShape = kODNULL; //shape->Copy(ev);
  465.         
  466.         // WARNING: If a part wants to have a specific used shape when a display frame
  467.         // is added it can not be embedded into AppleTest_Container because of a bug
  468.         // in Container's UsedShapeChanged method! Fortunately many parts, including NoPart,
  469.         // use the entire frame shape as their used shape when in frame view.
  470.     }
  471.     
  472.     SOM_CATCH_ALL
  473.     SOM_ENDTRY
  474.     
  475.     return usedShape;
  476. }
  477.  
  478. //--------------------------------------------------------------------
  479. // SetUserMessage
  480. //--------------------------------------------------------------------
  481.  
  482. SOM_Scope void SOMLINK NoPartSetUserMessage( Apple_NoPart *somSelf, Environment *ev,
  483.         ODError err,
  484.         ODIText *editorName,
  485.         corbastring param )
  486. {
  487.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  488.     Apple_NoPartMethodDebug("Apple_NoPart","SetUserMessage");
  489.     
  490.     SOM_TRY
  491.     
  492.     if( editorName && GetITextStringLength(editorName)==0 ) {
  493.         DisposeIText(editorName);
  494.         editorName = kODNULL;
  495.     }
  496.     
  497.     if( err == 0 )
  498.         err = editorName ?kFakeErrNoEditor :kFakeErrNoEditorNoName;
  499.     _fUserMessageID = err;
  500.     _fUserMessageEditorName = editorName;
  501.     if( param )
  502.         _fUserMessageParam = ODISOStrFromCStr(param);
  503.     
  504.     SOM_CATCH_ALL
  505.     SOM_ENDTRY
  506. }
  507.  
  508.  
  509. //--------------------------------------------------------------------
  510. // ComputeButtonLocation
  511. //--------------------------------------------------------------------
  512.  
  513. SOM_Scope void SOMLINK NoPartComputeButtonLocation( Apple_NoPart *somSelf, Environment *ev,
  514.         ODFrame *frame,
  515.         Rect *loc,
  516.         Rect *textBox )
  517. {
  518.     //Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  519.     Apple_NoPartMethodDebug("Apple_NoPart","ComputeButtonLocation");
  520.     
  521.     SOM_TRY
  522.     
  523.     // Load icon now since caller will presumably need it:
  524.     if( !gButtonIcon ) {
  525.         CUsingLibraryResources r;
  526.         OSErr err= GetIconSuite(&gButtonIcon,kNoPartButtonIconResID,kSelectorAllAvailableData);
  527.         WASSERTM(err==noErr||err==memFullErr,"Can't get NoPart button");
  528.     }
  529.  
  530.     TempODShape usedShape = frame->AcquireUsedShape(ev,kODNULL);
  531.     Rect used = (**(usedShape->GetQDRegion(ev))).rgnBBox;
  532.     InsetRect(&used,3,3); // allow for border
  533.     
  534.     // Preferentially put the button below the icon.
  535.     // If the frame isn't tall enough, put it to the right.
  536.     // If it's not even wide enough, put it at the bottom right.
  537.     
  538.     loc->left = used.left;
  539.     loc->top  = used.top;
  540.     if( kButtonPrefTop + kButtonHeight <= Height(used) ) {
  541.         loc->left += kButtonPrefLeft;
  542.         loc->top  += kButtonPrefTop;
  543.     } else if( kButtonAltLeft + kButtonWidth <= Width(used) ) {
  544.         loc->left += kButtonAltLeft;
  545.         loc->top  += kButtonAltTop;
  546.     } else {
  547.         loc->left = used.right-kButtonWidth;
  548.         loc->top  = used.bottom-kButtonHeight;
  549.     }
  550.     
  551.     textBox->left = loc->left + kButtonWidth + 2;    // Put text to right of button
  552.     textBox->top  = loc->top - 2;
  553.     if( used.right-textBox->left < kMinTextWidth ) {
  554.         textBox->left -= kButtonWidth+2;            // ...but if no room move it below
  555.         textBox->top  += kButtonHeight+4;
  556.     }
  557.     
  558.     textBox->right = used.right;
  559.     textBox->bottom= used.bottom;
  560.     
  561.     loc->right = loc->left + kODLargeIconSize;                    // Icon utils want exact 32x32 rect
  562.     loc->bottom= loc->top  + kODLargeIconSize;
  563.     
  564.     if( Width(*textBox) < kMinTextWidth || Height(*textBox)< kMinTextHeight)
  565.         textBox->bottom=textBox->top;                // Force empty if it's too small
  566.         
  567.     SOM_CATCH_ALL
  568.     SOM_ENDTRY
  569.     
  570. }
  571.  
  572.  
  573. static void
  574. Substitute( Handle text, Str255 replacement, int which )
  575. {
  576. //    unsigned char whichStr[3] = "\p^0";
  577. //  we replace the last statement with the next to get around compiler problem
  578.     unsigned char whichStr[3] = "\2^";
  579.     whichStr[2] = '0'+which;
  580.     Handle replaceH;
  581.     THROW_IF_ERROR( PtrToHand(&replacement[1],&replaceH,replacement[0]) );
  582.     ReplaceText(text,replaceH,whichStr);
  583.     DisposeHandle(replaceH);
  584. }
  585.  
  586.  
  587. //--------------------------------------------------------------------
  588. // ComputeUserMessage
  589. //--------------------------------------------------------------------
  590.  
  591. SOM_Scope ODIText SOMLINK NoPartComputeUserMessage( Apple_NoPart *somSelf, Environment *ev )
  592. {
  593.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  594.     Apple_NoPartMethodDebug("Apple_NoPart","ComputeUserMessage");
  595.     
  596.     ODIText itext = {0,0,0};
  597.  
  598.     SOM_TRY
  599.     
  600.     Str255 messageStr;
  601.     ODBoolean noSpecific = kODFalse;
  602.     if( ! LookupString(_fUserMessageID,kNoPartMessageTableID,messageStr) ) {
  603.         // No specific message. Get generic message & remember to lookup Shell msg later:
  604.         CUsingLibraryResources r;
  605.         GetIndString(messageStr,kNoPartMessageTableID,1);
  606.         noSpecific = kODTrue;
  607.     }
  608.     
  609.     Handle messageH = kODNULL;
  610.     THROW_IF_ERROR( PtrToHand(&messageStr[1],&messageH,messageStr[0]) );
  611.     TempODHandle tempMessageH = messageH; // ensure deletion
  612.     
  613.     Str255 editor;
  614.     if( _fUserMessageEditorName )
  615.         GetITextPString(_fUserMessageEditorName,editor);
  616.     else
  617.         editor[0] = '\0';
  618.  
  619.     Str255 param;
  620.     if( noSpecific )
  621.         LookupString(_fUserMessageID,kODErrUserID,param);    // Get Shell's message as param
  622.     else                                                    // (requires access to Shell rsrcs!)
  623.         CopyISOStr2PStr(param,_fUserMessageParam);
  624.     
  625.  
  626.     Str31 errStr;
  627.     NumToString(_fUserMessageID,errStr);
  628.  
  629.     Substitute(messageH, editor, 1);
  630.     Substitute(messageH, param,  2);
  631.     Substitute(messageH, errStr, 3);
  632.  
  633.     InitIText(&itext);
  634.     HLock(messageH);
  635.     SetITextText(&itext, (ODUByte*)*messageH, GetHandleSize(messageH));
  636.     ODScriptCode script = FontToScript(GetAppFont());
  637.     ODLangCode lang = GetScriptVariable(script, smScriptLang);
  638.     SetITextScriptCode(&itext, script);
  639.     SetITextLangCode(&itext, lang);
  640.     
  641.     SOM_CATCH_ALL
  642.     SOM_ENDTRY
  643.     
  644.     return itext;
  645. }
  646.  
  647.  
  648. //--------------------------------------------------------------------
  649. // Draw
  650. //--------------------------------------------------------------------
  651.  
  652. SOM_Scope void  SOMLINK NoPartDraw(Apple_NoPart *somSelf, Environment *ev,
  653.         ODFacet* facet, ODShape* invalidShape)
  654. {
  655.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  656.     Apple_NoPartMethodDebug("Apple_NoPart","Draw");
  657.  
  658. ODUnused(invalidShape);
  659.     
  660.     SOM_TRY
  661.     
  662.     if (!facet)
  663.     {
  664.         WARN("facet == kODNULL");
  665.         THROW(kODErrIllegalNullInput);
  666.     }
  667.  
  668.     ODFrame*    frame = facet->GetFrame(ev);
  669.     ODTypeToken view = frame->GetViewType(ev);
  670.     
  671.     //ODWindow*    window = facet->GetWindow(ev);
  672.  
  673.     // Check to see if the frame is selected and in an active window
  674.     //    if ( facet->GetHighlight(ev) == kODFullHighlight &&
  675.     //         window->IsActive(ev) )
  676.     //        transformType = kTransformSelected;
  677.  
  678.     TempODShape tempUsedShape = frame->AcquireUsedShape(ev, kODNULL);
  679.     TempODShape usedShape = tempUsedShape->Copy(ev);
  680.     TempODTransform transform = facet->AcquireFrameTransform(ev,kODNULL);
  681.     usedShape->Transform(ev,transform);
  682.  
  683.     RgnHandle usedRgn = usedShape->GetQDRegion(ev);
  684.     // compensate for the fact that FocusLib is going to set the origin below.
  685.     OffsetRgn(usedRgn, -(*usedRgn)->rgnBBox.left, -(*usedRgn)->rgnBBox.top);
  686.     
  687.     // Now it's time to draw:
  688.     CFocusFrame foc(ev,facet);
  689.     CPenInfo penInfo;    // Set pen normal, foreground black, background white.
  690.     
  691.     if (_fIconFamily == kODNULL)
  692.         _fIconFamily = ODGetIconFamily(ev, frame);
  693.  
  694.     if ( view == _fSession->Tokenize(ev, kODViewAsLargeIcon) || 
  695.                     view == _fSession->Tokenize(ev, kODViewAsSmallIcon) )
  696.     {            
  697.         EraseRgn(usedRgn);
  698.         FrameRgn(usedRgn);
  699.  
  700.          Rect iconRect; 
  701.         if (view == _fSession->Tokenize(ev, kODViewAsSmallIcon))
  702.             SetRect(&iconRect, 0, 0, kODSmallIconSize, kODSmallIconSize);
  703.         else
  704.             SetRect(&iconRect, 0, 0, kODLargeIconSize, kODLargeIconSize);
  705.                 
  706.         // Create rectangular shape
  707.         TempODShape rectShape = facet->CreateShape(ev);
  708.         ODRect rect(iconRect);
  709.         rectShape->SetRectangle(ev,&rect);
  710.         
  711.         ScaleOnlyShape(ev,transform,rectShape);
  712.         ODRect odrect;
  713.         rectShape->GetBoundingBox(ev,&odrect);
  714.         odrect.AsQDRect(iconRect);
  715.         
  716.         IconTransformType xform;
  717.         switch( facet->GetHighlight(ev) ) {
  718.             case kODFullHighlight:    xform = ttSelected; break;
  719.             case kODDimHighlight:    xform = ttDisabled; break;
  720.             default:                xform = ttNone; break;
  721.         }
  722.  
  723.         if (!_fIconFamily)
  724.             WARN("_fIconFamily == kODNULL");
  725.         else
  726.             PlotIconSuite(&iconRect, kAlignTopLeft, xform, _fIconFamily);
  727.     }
  728.     else if ( view == _fSession->Tokenize(ev, kODViewAsThumbnail) )
  729.     {
  730.         RGBColor rgb = {0x8000,0x8000,0x8000};
  731.         PixPatHandle ppat = NewPixPat();
  732.         MakeRGBPat(ppat, &rgb);
  733.         BackPixPat(ppat);
  734.  
  735.         EraseRgn(usedRgn);
  736.         FrameRgn(usedRgn);
  737.  
  738.         BackPat(&qd.white);
  739.         DisposePixPat(ppat);    // According to IM, QD will dispose it, but IM is wrong...
  740.             
  741.         Rect iconRect;
  742.         SetRect(&iconRect, 0, 0, kODLargeIconSize, kODLargeIconSize);
  743.  
  744.         // Create rectangular shape
  745.         TempODShape rectShape = facet->CreateShape(ev);
  746.         ODRect rect(iconRect);
  747.         rectShape->SetRectangle(ev,&rect);
  748.         
  749.         ScaleOnlyShape(ev,transform,rectShape);
  750.         ODRect odrect;
  751.         rectShape->GetBoundingBox(ev,&odrect);
  752.         odrect.AsQDRect(iconRect);
  753.  
  754.         IconTransformType xform;
  755.         switch( facet->GetHighlight(ev) ) {
  756.             case kODFullHighlight:    xform = ttSelected; break;
  757.             case kODDimHighlight:    xform = ttDisabled; break;
  758.             default:                xform = ttNone; break;
  759.         }
  760.  
  761.         OffsetRect(&iconRect,Width(iconRect)>>1,Height(iconRect)>>1);
  762.         if (!_fIconFamily)
  763.             WARN("_fIconFamily == kODNULL");
  764.         else
  765.             PlotIconSuite(&iconRect, kAlignAbsoluteCenter, xform, _fIconFamily);
  766.     }
  767.     else // if ( view == _fSession->Tokenize(ev, kODViewAsFrame) )
  768.     {
  769.         RGBColor rgb = {0x8000,0x8000,0x8000};
  770.         PixPatHandle ppat = NewPixPat();
  771.         MakeRGBPat(ppat, &rgb);
  772.         BackPixPat(ppat);
  773.  
  774.         EraseRgn(usedRgn);
  775.         FrameRgn(usedRgn);
  776.         
  777.         // Draw button & message, if any
  778.         {
  779.             Rect rButton, rText;
  780.             somSelf->ComputeButtonLocation(ev, frame, &rButton, &rText);
  781.             if( gButtonIcon )
  782.                 PlotIconSuite(&rButton, kAlignTopLeft, kTransformNone, gButtonIcon);
  783.             
  784.             if( !EmptyRect(&rText) ) {
  785.                 ODIText text = somSelf->ComputeUserMessage(ev);
  786.                 short savedFont = qd.thePort->txFont;
  787.                 short savedSize = qd.thePort->txSize;
  788.                 long fontsize = GetScriptVariable(GetITextScriptCode(&text),
  789.                                                   smScriptSmallFondSize);
  790.                 TextFont( fontsize >> 16 );
  791.                 TextSize( fontsize & 0xFFFF );
  792.                 TextFace(0);
  793.                 
  794.                 FontInfo i;
  795.                 GetFontInfo(&i);
  796.                 rText.bottom -= Height(rText) % (i.ascent+i.descent+i.leading); // no partial lines
  797.                 
  798.                 TETextBox( GetITextPtr(&text), GetITextStringLength(&text), &rText, teFlushDefault );
  799.  
  800.                 TextFont(savedFont);
  801.                 TextSize(savedSize);
  802.                 DisposeITextStruct(text);
  803.             }
  804.         }
  805.         
  806.         BackPat(&qd.white);
  807.         DisposePixPat(ppat);    // According to IM, QD will dispose it, but IM is wrong...
  808.         
  809.         Rect iconRect;
  810.         
  811.         if (view == _fSession->Tokenize(ev, kODViewAsSmallIcon))
  812.         SetRect(&iconRect, 0, 0, kODSmallIconSize, kODSmallIconSize);
  813.     else
  814.         SetRect(&iconRect, 0, 0, kODLargeIconSize, kODLargeIconSize);
  815.         
  816.         OffsetRect(&iconRect,2,2);        // Position icon away from border
  817.         if (!_fIconFamily)
  818.             WARN("_fIconFamily == kODNULL");
  819.         else
  820.             PlotIconSuite(&iconRect, kAlignTopLeft, kTransformNone, _fIconFamily);
  821.     }
  822.  
  823.     SOM_CATCH_ALL
  824.     SOM_ENDTRY
  825. }
  826.  
  827.  
  828. //--------------------------------------------------------------------
  829. // Open
  830. //--------------------------------------------------------------------
  831.  
  832. SOM_Scope ODID  SOMLINK NoPartOpen(Apple_NoPart *somSelf, Environment *ev,
  833.         ODFrame* frame)
  834. {
  835.     /*    Open just calls ShowUserMessage (q.v.) which will first attempt
  836.         to rebind if this makes sense.
  837.         In the special case where this is the root part, Open will put
  838.         up an appropriate alert and always return false.
  839.         If rebinding fails, I throw kODErrAlreadyNotified to inform the
  840.         caller that the Open failed but that I've already alerted the
  841.         user.
  842.         In the case of the root part, the error will prevent the document
  843.         from opening. If it was the first/only document, the process
  844.         quits. Yay! */
  845.         
  846.     //Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  847.     Apple_NoPartMethodDebug("Apple_NoPart","Open");
  848.  
  849.     SOM_TRY
  850.     
  851.     if( ! somSelf->ShowUserMessage(ev,kODTrue) )
  852.         THROW(kODErrAlreadyNotified);
  853.     
  854.     SOM_CATCH_ALL
  855.     SOM_ENDTRY
  856.     return 0;
  857. }
  858.  
  859.  
  860. //--------------------------------------------------------------------
  861. // HandleEvent
  862. //--------------------------------------------------------------------
  863.  
  864. SOM_Scope ODBoolean  SOMLINK NoPartHandleEvent(Apple_NoPart *somSelf, Environment *ev,
  865.         ODEventData* event,
  866.         ODFrame* frame,
  867.         ODFacet* facet,
  868.         ODEventInfo* eventInfo)
  869. {
  870.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  871.     Apple_NoPartMethodDebug("Apple_NoPart","HandleEvent");
  872.     
  873.     ODBoolean    tWasHandled = kODFalse;
  874.  
  875.     SOM_TRY
  876.  
  877.     switch (event->what)
  878.     {
  879.         case nullEvent:
  880.             break;
  881.         
  882.         case mouseDown:
  883.             if ( somSelf->CheckDoubleClick(ev, event) )
  884.             {
  885.                 _fIsDoubleClick = kODTrue;
  886.             }
  887.             else
  888.             {
  889.                 Rect rButton, rText;
  890.                 somSelf->ComputeButtonLocation(ev, frame, &rButton, &rText);
  891.                 if( PtInIconSuite(eventInfo->where.AsQDPoint(),&rButton,kAlignTopLeft,gButtonIcon) ) {
  892.                     // Track click in button:
  893.                     if( somSelf->TrackButton(ev,facet,&rButton) )
  894.                         (void) somSelf->ShowUserMessage(ev,kODTrue);
  895.                 } else {
  896.                     // Otherwise pass click to container to select this frame:
  897.                     TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
  898.                     if (containingFrame)
  899.                     {
  900.                         event->what = kODEvtMouseDownEmbedded;
  901.                         eventInfo->embeddedFrame = frame;
  902.                         eventInfo->embeddedFacet = facet;
  903.                         TempODPart part = containingFrame->AcquirePart(ev);
  904.                         tWasHandled = part->
  905.                             HandleEvent(ev,event,containingFrame,facet->GetContainingFacet(ev),eventInfo);
  906.                     }
  907.                 }
  908.             }
  909.             break;
  910.  
  911.         case mouseUp:
  912.  
  913.             tWasHandled = kODTrue;
  914.             somSelf->CaptureMouseUpEvent(ev, event, frame);
  915.             if (_fIsDoubleClick)
  916.             {
  917.                 somSelf->Open(ev, frame);
  918.                 tWasHandled = kODTrue;
  919.                 _fIsDoubleClick = kODFalse;
  920.             }
  921.             break;
  922.  
  923.         default:
  924.             return kODFalse;
  925.     }
  926.     
  927.     SOM_CATCH_ALL
  928.         tWasHandled = kODFalse;
  929.     SOM_ENDTRY
  930.     
  931.     return tWasHandled;
  932. }
  933.  
  934.  
  935. //--------------------------------------------------------------------
  936. // TrackButton
  937. //--------------------------------------------------------------------
  938.  
  939. SOM_Scope ODBoolean  SOMLINK NoPartTrackButton(Apple_NoPart *somSelf, Environment *ev,
  940.         ODFacet *facet,
  941.         Rect *button)
  942. {
  943.     //Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  944.     Apple_NoPartMethodDebug("Apple_NoPart","TrackButton");
  945.  
  946.     ODBoolean inside = kODFalse;
  947.  
  948.     SOM_TRY
  949.     
  950.     CFocusFrame foc(ev,facet);
  951.  
  952.     do {
  953.         Point mouse;
  954.         GetMouse(&mouse);
  955.         ODBoolean nowinside = PtInIconSuite(mouse,button,kAlignTopLeft,gButtonIcon);
  956.         if( nowinside != inside ) {
  957.             PlotIconSuite(button, kAlignTopLeft, nowinside ?kTransformSelected:kTransformNone, gButtonIcon);
  958.             inside = nowinside;
  959.         }
  960.     } while( StillDown() );
  961.  
  962.     if( inside )
  963.         PlotIconSuite(button, kAlignTopLeft, kTransformNone, gButtonIcon);
  964.         
  965.     SOM_CATCH_ALL
  966.     SOM_ENDTRY
  967.     
  968.     return inside;
  969. }
  970.  
  971.  
  972. static ODBoolean
  973. IsRootPartSU( Environment *ev, ODStorageUnit *su )
  974. {
  975.     TempODStorageUnit rootSU = ODAcquireRootPartSUOfDraft(ev,su->GetDraft(ev));
  976.     return su==rootSU;
  977. }
  978.  
  979.  
  980. static void
  981. GetDocumentName( Environment *ev, ODStorageUnit *su, Str63 name )
  982. {
  983.     TempODContainerIDStruct id( su->GetDraft(ev)->GetDocument(ev)->GetContainer(ev)->GetID(ev));
  984.     ASSERT(id->_length>=8 && id->_length<=sizeof(FSSpec), kODErrAssertionFailed);
  985.     CopyPascalString(name, ((FSSpec*)id->_buffer)->name);
  986. }
  987.  
  988.  
  989. //--------------------------------------------------------------------
  990. // Rebind
  991. //--------------------------------------------------------------------
  992.  
  993. SOM_Scope ODBoolean  SOMLINK NoPartRebind(Apple_NoPart *somSelf, Environment *ev )
  994. {
  995.     /*    Rebinding is tricky when called from the part itself.
  996.         The part _will_ be deleted whether or not the operation succeeded!
  997.         Do not use 'somSelf' or 'somThis' after calling this method. */
  998.         
  999.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1000.     Apple_NoPartMethodDebug("Apple_NoPart","Rebind");
  1001.     
  1002.     ODBoolean status = kODTrue;
  1003.     
  1004.     SOM_TRY
  1005.     
  1006.     if( ODGetDraft(ev, _fStorageUnit)->GetPermissions(ev) < kODDPSharedWrite )
  1007.         THROW(kODErrInvalidPermissions);
  1008.     // Unfortunately one can't swap editors in a read-only document because
  1009.     // UseEditor externalizes the WindowState...
  1010.     
  1011.     TempODEditor theEditor = _fSession->GetBinding(ev)->
  1012.                                   ChooseEditorForPart( ev, _fStorageUnit, kODNULL );
  1013.     ODBoolean editorIsNoPart = ODISOStrEqual(theEditor, kODBlackBoxHandlerOfLastResort);
  1014.                           
  1015.     if( !editorIsNoPart )
  1016.         _fPartWrapper->UseEditor(ev,theEditor);
  1017.     else
  1018.         status = kODFalse;
  1019.  
  1020.     SOM_CATCH_ALL
  1021.         status = kODFalse;
  1022.         SetErrorCode(kODNoError);        // don't propagate any exception
  1023.     SOM_ENDTRY
  1024.     
  1025.     return status;
  1026. }
  1027.  
  1028.  
  1029. static ODBoolean
  1030. CanTranslate( Environment *ev, ODSession *session, ODPartWrapper *partWrapper )
  1031. {
  1032.     // This function was blatantly stolen from TransDlg.cpp
  1033.     TRY{
  1034.         ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  1035.         ODStorageUnit* storageUnit = partWrapper->GetStorageUnit(ev);
  1036.         
  1037.         // Create the list of kinds and translations
  1038.         TempODTypeList kindList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  1039.         
  1040.         ContentValueTypes(storageUnit, kindList);
  1041.  
  1042.         { TempODEditor tempEditor = GetCurrentEditorForPart(partWrapper);
  1043.           GetAllKindsForEditor(nsm, kindList, tempEditor);
  1044.         }
  1045.  
  1046.         TempODTypeList translateToList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  1047.         
  1048.         OrderedCollection translateFromList;
  1049.         GetDestinationKindsList(kindList, translateToList, &translateFromList, session);
  1050.         
  1051.         return (translateToList->Count(ev) > 0);
  1052.     }CATCH_ALL{
  1053.         WARN("CanTranslate got err %ld",ErrorCode());
  1054.     }ENDTRY
  1055.     return kODFalse;
  1056. }
  1057.  
  1058.  
  1059. //--------------------------------------------------------------------
  1060. // ShowUserMessage
  1061. //--------------------------------------------------------------------
  1062.  
  1063. SOM_Scope ODBoolean SOMLINK NoPartShowUserMessage( Apple_NoPart *somSelf, Environment *ev,
  1064.         ODBoolean allowRebind )
  1065. {
  1066.     /*    There are a couple of things going on here.
  1067.         1. First try reloading the original editor. If we succeed, just return.
  1068.         2. Display the alert explaining why the part couldn't be opened.
  1069.             (If this is the root part, use a special alert that explains why the _document_
  1070.              couldn't be opened.)
  1071.     */
  1072.     
  1073.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1074.     Apple_NoPartMethodDebug("Apple_NoPart","ShowUserMessage");
  1075.     
  1076.     SOM_TRY
  1077.  
  1078.     // Check whether this is the root part, and if not, attempt to rebind:
  1079.     short id;
  1080.     ODBoolean writeable = ODGetDraft(ev, _fStorageUnit)->GetPermissions(ev) >= kODDPSharedWrite;
  1081.     Str63 docName = "\p";
  1082.     if( IsRootPartSU(ev,_fStorageUnit) ) {
  1083.         id = kNoPartRootDlogID;                // special alert for root part
  1084.         GetDocumentName(ev,_fStorageUnit,docName);
  1085.     } else {
  1086.         // First try to rebind if doc is writeable:
  1087.         id = kNoPartDlogID;
  1088.         if( allowRebind && writeable ) {
  1089.             ODPart *wrapper = _fPartWrapper;
  1090.             if( somSelf->Rebind(ev) )
  1091.                 return kODTrue;
  1092.             else {
  1093.                 /* We're in a precarious state now: Even though the rebind failed,
  1094.                     the part has been deleted. To get around this, find the _new_
  1095.                     part and tell it to show the message. */
  1096.                 Apple_NoPart *part = CAST(wrapper->GetRealPart(ev),Apple_NoPart);
  1097.                 wrapper->ReleaseRealPart(ev);
  1098.                 part->ShowUserMessage(ev,kODFalse);
  1099.                 return kODFalse;
  1100.             }
  1101.         }
  1102.     }
  1103.     
  1104.     // Determine the text to be put into the alert:
  1105.     ODIText msg = somSelf->ComputeUserMessage(ev);
  1106.     Str255 message;
  1107.     GetITextPString(&msg,message);
  1108.     DisposeITextStruct(msg);
  1109.     
  1110.     Str31 errStr;
  1111.     NumToString(_fUserMessageID,errStr);
  1112.     
  1113.     ODBoolean canTranslate;
  1114.     Str255 translateStr;
  1115.     if( _fUserMessageID==kFakeErrNoEditor || _fUserMessageID==kFakeErrNoEditorNoName ) {
  1116.         canTranslate = writeable && CanTranslate(ev,_fSession,_fPartWrapper);
  1117.         CUsingLibraryResources r;
  1118.         GetIndString(translateStr,kNoPartTranslationStrID, 1+canTranslate);
  1119.     } else {
  1120.         canTranslate = kODFalse;
  1121.         translateStr[0] = '\0';
  1122.     }
  1123.     
  1124.     ParamText(message,docName,translateStr,errStr);
  1125.  
  1126.     // Show the alert (which is really a dialog so we can play with the Translate button):
  1127.     short result = ok;
  1128.     if ( _fUserMessageID != kODErrAlreadyNotified )        // should test earlier?
  1129.     {
  1130.         CUsingLibraryResources r;
  1131.         DialogPtr dlog = ODGetNewDialog(ev,id,_fSession,kODFalse);
  1132.         if( !dlog ) return kODFalse;
  1133.         SetDialogDefaultItem(dlog,ok);
  1134.  
  1135.         if( _fUserMessageID==kFakeErrNoEditor || _fUserMessageID==kFakeErrNoEditorNoName ) {
  1136.             HideDialogItem(dlog,kErrorNumberItem);
  1137.             if( !canTranslate ) {
  1138.                 short typ;
  1139.                 ControlHandle but;
  1140.                 Rect box;
  1141.                 GetDialogItem(dlog,kTranslateItem,&typ,(Handle*)&but,&box);
  1142.                 HiliteControl(but,kControlDisabledPart);
  1143.             }
  1144.         } else
  1145.             HideDialogItem(dlog,kTranslateItem);
  1146.         
  1147.         _fSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  1148.         SetPort(dlog);
  1149.         ShowWindow(dlog);
  1150.         SelectWindow(dlog);
  1151.         TempODMenuBar menu = _fSession->GetWindowState(ev)->AcquireCurrentMenuBar(ev);
  1152.         ODDialogBegin(ev,_fSession,menu,dlog);
  1153.         ModalDialog(GetODDialogFilter(),&result);
  1154.         DisposeDialog(dlog);
  1155.         ODDialogEnd();
  1156.         _fSession->GetWindowState(ev)->ActivateFrontWindows( ev );
  1157.     }
  1158.  
  1159.     // Run the translation dialog if the user pushed the "Translate..." button:
  1160.     if( result==kTranslateItem ) {
  1161.         TRY{
  1162.             ODTranslation* translation = _fSession->GetTranslation(ev);
  1163.             result= translation->ShowPartTranslateDialog(ev, _fPartWrapper);
  1164.         }CATCH_ALL{
  1165.             WARN("Translation returned err %ld",ErrorCode());
  1166.             result = kODFalse;
  1167.         }ENDTRY
  1168.         return result;
  1169.     }
  1170.     
  1171.     SOM_CATCH_ALL
  1172.     SOM_ENDTRY
  1173.     
  1174.     return kODFalse;
  1175. }
  1176.  
  1177.  
  1178.  
  1179. //--------------------------------------------------------------------
  1180. // CaptureMouseUpEvent
  1181. //--------------------------------------------------------------------
  1182.  
  1183. SOM_Scope ODBoolean  SOMLINK NoPartCaptureMouseUpEvent(Apple_NoPart *somSelf, Environment *ev,
  1184.         ODEventData* event,
  1185.         ODFrame* frame)
  1186. {
  1187.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1188.     Apple_NoPartMethodDebug("Apple_NoPart","NoPartCaptureMouseUpEvent");
  1189.  
  1190.     SOM_TRY
  1191.         // do this for double-click monitoring
  1192.     _fMouseWhen  = event->when;
  1193.     _fMouseWhere = event->where;
  1194.     
  1195.     SOM_CATCH_ALL
  1196.     SOM_ENDTRY
  1197.  
  1198.     return kODTrue;
  1199. }
  1200.  
  1201.  
  1202. //--------------------------------------------------------------------
  1203. // CheckDoubleClick
  1204. //--------------------------------------------------------------------
  1205.  
  1206. SOM_Scope ODBoolean  SOMLINK NoPartCheckDoubleClick(Apple_NoPart *somSelf, Environment *ev,
  1207.         ODEventData* event)
  1208. {
  1209.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1210.     Apple_NoPartMethodDebug("Apple_NoPart","NoPartCheckDoubleClick");
  1211.  
  1212.     ODBoolean    isDoubleClick = kODFalse; ODVolatile(isDoubleClick);
  1213.     
  1214.     SOM_TRY
  1215.     
  1216.     Rect        testRect;
  1217.  
  1218.     isDoubleClick = (event->when - _fMouseWhen) <= GetDblTime();
  1219.     
  1220.     SetRect(&testRect, _fMouseWhere.IntX( ), _fMouseWhere.IntY( ), 
  1221.                         _fMouseWhere.IntX( ), _fMouseWhere.IntY( ));
  1222.     InsetRect(&testRect, -2, -2);
  1223.     
  1224.     isDoubleClick &= PtInRect(event->where, &testRect);
  1225.  
  1226.     SOM_CATCH_ALL
  1227.     SOM_ENDTRY
  1228.  
  1229.     return isDoubleClick;
  1230. }
  1231.  
  1232. //--------------------------------------------------------------------
  1233. // ViewTypeChanged
  1234. //--------------------------------------------------------------------
  1235.  
  1236. SOM_Scope void  SOMLINK NoPartViewTypeChanged(Apple_NoPart *somSelf, Environment *ev,
  1237.         ODFrame* frame)
  1238. {
  1239.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1240.     Apple_NoPartMethodDebug("Apple_NoPart","ViewTypeChanged");
  1241.     
  1242.     SOM_TRY
  1243.     
  1244.     if (!frame) WARN("frame == kODNULL");
  1245.     else
  1246.     {
  1247.         // Change this frame's used shape to match the new view setting.
  1248.         // TempODShape newUsedShape = NoPartCalcNewUsedShape(ev, frame,_fIconFamily);    
  1249.         TempODShape newUsedShape = somSelf->CalcUsedShape(ev, frame);    
  1250.  
  1251.         frame->Invalidate(ev, kODNULL, kODNULL);
  1252.         frame->ChangeUsedShape(ev, newUsedShape, kODNULL);
  1253.         frame->Invalidate(ev, kODNULL, kODNULL);
  1254.  
  1255.     }
  1256.     
  1257.     SOM_CATCH_ALL
  1258.     SOM_ENDTRY
  1259.  
  1260. }
  1261.  
  1262.  
  1263. //--------------------------------------------------------------------
  1264. // FrameShapeChanged
  1265. //--------------------------------------------------------------------
  1266.  
  1267. SOM_Scope void  SOMLINK NoPartFrameShapeChanged(Apple_NoPart *somSelf, Environment *ev,
  1268.         ODFrame* frame)
  1269. {
  1270.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1271.     Apple_NoPartMethodDebug("Apple_NoPart","FrameShapeChanged");
  1272.     
  1273.     SOM_TRY
  1274.  
  1275.     if (!frame) WARN("frame == kODNULL");
  1276.     else
  1277.     {
  1278.         // Adjust the used shape for the new frame shape.
  1279.         TempODShape usedShape = somSelf->CalcUsedShape(ev, frame);    
  1280.         if ( usedShape )
  1281.             frame->ChangeUsedShape(ev, usedShape, kODNULL);
  1282.     }
  1283.  
  1284.     SOM_CATCH_ALL
  1285.     SOM_ENDTRY
  1286. }
  1287.  
  1288. //--------------------------------------------------------------------
  1289. // DisplayFrameAdded
  1290. //--------------------------------------------------------------------
  1291.  
  1292. SOM_Scope void  SOMLINK NoPartDisplayFrameAdded(Apple_NoPart *somSelf, Environment *ev,
  1293.         ODFrame* frame)
  1294. {
  1295. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1296.     Apple_NoPartMethodDebug("Apple_NoPart","DisplayFrameAdded");
  1297.     
  1298.     SOM_TRY
  1299.  
  1300.     if (!frame) WARN("frame == kODNULL");
  1301.     else
  1302.         somSelf->FrameShapeChanged(ev,frame); // set frames used shape
  1303.  
  1304.     SOM_CATCH_ALL
  1305.     SOM_ENDTRY
  1306. }
  1307.  
  1308. //--------------------------------------------------------------------
  1309. // DisplayFrameConnected
  1310. //--------------------------------------------------------------------
  1311.  
  1312. SOM_Scope void  SOMLINK NoPartDisplayFrameConnected(Apple_NoPart *somSelf, Environment *ev,
  1313.         ODFrame* frame)
  1314. {
  1315. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1316.     Apple_NoPartMethodDebug("Apple_NoPart","DisplayFrameConnected");
  1317.     
  1318.     SOM_TRY
  1319.  
  1320.     if (!frame) WARN("frame == kODNULL");
  1321.     else
  1322.       somSelf->FrameShapeChanged(ev,frame); // set frames used shape
  1323.  
  1324.     SOM_CATCH_ALL
  1325.     SOM_ENDTRY
  1326. }
  1327.  
  1328.  
  1329. //--------------------------------------------------------------------
  1330. // CloneInto
  1331. //--------------------------------------------------------------------
  1332.  
  1333. SOM_Scope void  SOMLINK NoPartCloneInto(Apple_NoPart *somSelf, Environment *ev,
  1334.         ODDraftKey key,
  1335.         ODStorageUnit* storageUnit,
  1336.         ODFrame* initiatingFrame)
  1337. {
  1338.     Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1339.     Apple_NoPartMethodDebug("Apple_NoPart","CloneInto");
  1340.     
  1341.     SOM_TRY
  1342.     
  1343.     // Blindly clone the entire storage unit.
  1344.     
  1345.     _fStorageUnit->CloneInto(ev,key,storageUnit,kODIDAll);
  1346.  
  1347.     // We don't call our parent because meta data about NoPart is 
  1348.     // ephemeral and need not be cloned persistently.
  1349.     
  1350.     SOM_CATCH_ALL
  1351.     SOM_ENDTRY
  1352. }
  1353.  
  1354. //--------------------------------------------------------------------
  1355. // Stub methods
  1356. //--------------------------------------------------------------------
  1357.  
  1358.  
  1359. #pragma mark -------stubs-------
  1360.  
  1361. SOM_Scope void  SOMLINK NoPartFacetAdded(Apple_NoPart *somSelf, Environment *ev,
  1362.         ODFacet* facet)
  1363. {
  1364.     //Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1365.     Apple_NoPartMethodDebug("Apple_NoPart","FacetAdded");
  1366. }
  1367.  
  1368. SOM_Scope void  SOMLINK NoPartGeometryChanged(Apple_NoPart *somSelf, Environment *ev,
  1369.         ODFacet* facet,
  1370.         ODBoolean clipShapeChanged,
  1371.         ODBoolean externalTransformChanged)
  1372. {
  1373.     //Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1374.     Apple_NoPartMethodDebug("Apple_NoPart","GeometryChanged");
  1375. }
  1376.  
  1377. SOM_Scope void  SOMLINK NoPartContainingPartPropertiesUpdated(Apple_NoPart *somSelf, Environment *ev,
  1378.         ODFrame* frame,
  1379.         ODStorageUnit* propertyUnit)
  1380. {
  1381. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1382.     Apple_NoPartMethodDebug("Apple_NoPart","ContainingPartPropertiesUpdated");
  1383.  
  1384. }
  1385.  
  1386. SOM_Scope void  SOMLINK NoPartDisplayFrameRemoved(Apple_NoPart *somSelf, Environment *ev,
  1387.         ODFrame* frame)
  1388. {
  1389. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1390.     Apple_NoPartMethodDebug("Apple_NoPart","DisplayFrameRemoved");
  1391.  
  1392. }
  1393.  
  1394. SOM_Scope void  SOMLINK NoPartDisplayFrameClosed(Apple_NoPart *somSelf, Environment *ev,
  1395.         ODFrame* frame)
  1396. {
  1397. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1398.     Apple_NoPartMethodDebug("Apple_NoPart","DisplayFrameClosed");
  1399. }
  1400.  
  1401. SOM_Scope void  SOMLINK NoPartAttachSourceFrame(Apple_NoPart *somSelf, Environment *ev,
  1402.         ODFrame* frame,
  1403.         ODFrame* sourceFrame)
  1404. {
  1405. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1406.     Apple_NoPartMethodDebug("Apple_NoPart","AttachSourceFrame");
  1407. }
  1408.  
  1409. SOM_Scope void  SOMLINK NoPartPresentationChanged(Apple_NoPart *somSelf, Environment *ev,
  1410.         ODFrame* frame)
  1411. {
  1412. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1413.     Apple_NoPartMethodDebug("Apple_NoPart","PresentationChanged");
  1414. }
  1415.  
  1416. SOM_Scope void  SOMLINK NoPartSequenceChanged(Apple_NoPart *somSelf, Environment *ev,
  1417.         ODFrame* frame)
  1418. {
  1419. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1420.     Apple_NoPartMethodDebug("Apple_NoPart","SequenceChanged");
  1421. }
  1422.  
  1423. SOM_Scope ODInfoType  SOMLINK NoPartReadPartInfo(Apple_NoPart *somSelf, Environment *ev,
  1424.         ODFrame* frame,
  1425.         ODStorageUnitView* storageUnitView)
  1426. {
  1427. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1428.     Apple_NoPartMethodDebug("Apple_NoPart","ReadPartInfo");
  1429.  
  1430.     return kODNULL;
  1431. }
  1432.  
  1433. SOM_Scope void  SOMLINK NoPartWritePartInfo(Apple_NoPart *somSelf, Environment *ev,
  1434.         ODInfoType partInfo,
  1435.         ODStorageUnitView* storageUnitView)
  1436. {
  1437. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1438.     Apple_NoPartMethodDebug("Apple_NoPart","WritePartInfo");
  1439.  
  1440. }
  1441.  
  1442. SOM_Scope void  SOMLINK NoPartClonePartInfo(Apple_NoPart *somSelf, Environment *ev,
  1443.         ODDraftKey key,
  1444.         ODInfoType partInfo,
  1445.         ODStorageUnitView* storageUnitView,
  1446.         ODFrame* scopeFrame)
  1447. {
  1448. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1449.     Apple_NoPartMethodDebug("Apple_NoPart","ClonePartInfo");
  1450.  
  1451. }
  1452.  
  1453. SOM_Scope void  SOMLINK NoPartFacetRemoved(Apple_NoPart *somSelf, Environment *ev,
  1454.         ODFacet* facet)
  1455. {
  1456. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1457.     Apple_NoPartMethodDebug("Apple_NoPart","FacetRemoved");
  1458. }
  1459.  
  1460. SOM_Scope void  SOMLINK NoPartCanvasChanged(Apple_NoPart *somSelf, Environment *ev,
  1461.         ODFacet* facet)
  1462. {
  1463. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1464.     Apple_NoPartMethodDebug("Apple_NoPart","CanvasChanged");
  1465. }
  1466.  
  1467. SOM_Scope void  SOMLINK NoPartCanvasUpdated(Apple_NoPart *somSelf, Environment *ev,
  1468.         ODCanvas* canvas)
  1469. {
  1470. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1471.     Apple_NoPartMethodDebug("Apple_NoPart","CanvasUpdated");
  1472. }
  1473.  
  1474. SOM_Scope void  SOMLINK NoPartHighlightChanged(Apple_NoPart *somSelf, Environment *ev,
  1475.         ODFacet* facet)
  1476. {
  1477. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1478.     Apple_NoPartMethodDebug("Apple_NoPart","HighlightChanged");
  1479. }
  1480.  
  1481. SOM_Scope ODULong  SOMLINK NoPartGetPrintResolution(Apple_NoPart *somSelf, Environment *ev,
  1482.         ODFrame* frame)
  1483. {
  1484. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1485.     Apple_NoPartMethodDebug("Apple_NoPart","GetPrintResolution");
  1486.  
  1487.     return 0;
  1488. }
  1489.  
  1490. SOM_Scope void  SOMLINK NoPartLinkStatusChanged(Apple_NoPart *somSelf, Environment *ev,
  1491.         ODFrame* frame)
  1492. {
  1493. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1494.     Apple_NoPartMethodDebug("Apple_NoPart","LinkStatusChanged");
  1495. }
  1496.  
  1497. SOM_Scope ODBoolean  SOMLINK NoPartBeginRelinquishFocus(Apple_NoPart *somSelf, Environment *ev,
  1498.         ODTypeToken focus,
  1499.         ODFrame* ownerFrame,
  1500.         ODFrame* proposedFrame)
  1501. {
  1502. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1503.     Apple_NoPartMethodDebug("Apple_NoPart","BeginRelinquishFocus");
  1504.  
  1505.     return kODFalse;
  1506. }
  1507.  
  1508. SOM_Scope void  SOMLINK NoPartCommitRelinquishFocus(Apple_NoPart *somSelf, Environment *ev,
  1509.         ODTypeToken focus,
  1510.         ODFrame* ownerFrame,
  1511.         ODFrame* proposedFrame)
  1512. {
  1513. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1514.     Apple_NoPartMethodDebug("Apple_NoPart","CommitRelinquishFocus");
  1515. }
  1516.  
  1517. SOM_Scope void  SOMLINK NoPartAbortRelinquishFocus(Apple_NoPart *somSelf, Environment *ev,
  1518.         ODTypeToken focus,
  1519.         ODFrame* ownerFrame,
  1520.         ODFrame* proposedFrame)
  1521. {
  1522. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1523.     Apple_NoPartMethodDebug("Apple_NoPart","AbortRelinquishFocus");
  1524. }
  1525.  
  1526. SOM_Scope void  SOMLINK NoPartFocusAcquired(Apple_NoPart *somSelf, Environment *ev,
  1527.         ODTypeToken focus,
  1528.         ODFrame* ownerFrame)
  1529. {
  1530. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1531.     Apple_NoPartMethodDebug("Apple_NoPart","FocusAcquired");
  1532. }
  1533.  
  1534. SOM_Scope void  SOMLINK NoPartFocusLost(Apple_NoPart *somSelf, Environment *ev,
  1535.         ODTypeToken focus,
  1536.         ODFrame* ownerFrame)
  1537. {
  1538. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1539.     Apple_NoPartMethodDebug("Apple_NoPart","FocusLost");
  1540. }
  1541.  
  1542.  
  1543. SOM_Scope void  SOMLINK NoPartExternalizeKinds(Apple_NoPart *somSelf, Environment *ev,
  1544.         ODTypeList* kindset)
  1545. {
  1546. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1547.     Apple_NoPartMethodDebug("Apple_NoPart","ExternalizeKinds");
  1548. }
  1549.  
  1550. SOM_Scope void  SOMLINK NoPartChangeKind(Apple_NoPart *somSelf, Environment *ev,
  1551.         ODType kind)
  1552. {
  1553. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1554.     Apple_NoPartMethodDebug("Apple_NoPart","ChangeKind");
  1555. }
  1556.  
  1557. SOM_Scope void  SOMLINK NoPartAdjustMenus(Apple_NoPart *somSelf, Environment *ev,
  1558.         ODFrame* frame)
  1559. {
  1560. //  Apple_NoPartData *somThis = Apple_NoPartGetData(somSelf);
  1561.     Apple_NoPartMethodDebug("Apple_NoPart","AdjustMenus");
  1562. }
  1563.